<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta charset="UTF-8">
    <title>代办附件删除</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/global.css" media="all"/>
</head>
<body>
<div class="content-container" style="top: 0px;">
    <div class="widget-body no-padding">
        <table style="width: 1000px;" class="layui-hide" id="test" lay-filter="test"></table>
        <script type="text/html" id="itemTpl">
            <button type="button" lay-event="del" class="layui-btn layui-btn-sm" id="del"><i
                    class="layui-icon"></i>删除
            </button>
        </script>
    </div>
</div>
<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/plugin/fnReloadAjax.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript" src="../../js/plugin/jquery-download.js"></script>
<script type="text/javascript">
    var userId = $('.header-demo .layui-nav .layui-nav-item a span#userId', parent.document).text();

    //获取url后的参数值
    function getUrlParam(key) {
        var href = window.location.href;
        var url = href.split("?");
        if (url.length <= 1) {
            return "";
        }
        var params = url[1].split("&");
        for (var i = 0; i < params.length; i++) {
            var param = params[i].split("=");
            if (key == param[0]) {
                return param[1];
            }
        }
    }

    layui.use(['table', 'layer', 'form'], function () {
        var layer = layui.layer
            , table = layui.table
            , $ = layui.$;

        var id = getUrlParam("id");
        if (id==='' || id===null){
            id = 0;
            userId = 0;
        }
        table.render({
            elem: '#test',
            method: 'get',
            page: false,
            cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            url: '/mOverseeQuestions/file?id=' + id +'&userId='+userId,
            cols: [[
                {field: 'branch', title: '单位名称', width: '20%'}
                , {field: 'question', title: '问题项', width: '20%'}
                , {field: 'path', title: '附件名称', width: '53%'}
                , {field: '', title: '操作', width: '7%', toolbar: '#itemTpl', fixed: 'right', align: 'center'}
            ]]
        });

        //表头加粗
        $('th').css({'font-weight': 'bold'})

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            if (obj.event === 'del') {
                $.ajax({
                    url: '/mOverseeQuestions/deleteFile/' + obj.data.id,
                    type: 'get',
                    success: function () {
                        layer.msg("删除成功", {
                            icon: 1,
                            time: 1000
                        }, function () {
                            location.href = "delFile.html";
                        });
                    }
                })
            }
        });
    });
</script>
</body>
</html>